package heima3_2.cn.osc.presenter;


import java.util.List;

import heima3_2.cn.osc.base.OurTabBaseFragment;
import heima3_2.cn.osc.base.OurTabBasePresenter;
import heima3_2.cn.osc.model.bean.CollectBean;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by yaozhanlie on 2017/1/16.
 */

public class CollectSoftPresenter extends OurTabBasePresenter<CollectBean, CollectBean.FavoriteBean> {
    @Override
    protected void doRetrofitQuest() {
        Call<CollectBean> collectInfo = mRetrofitInterface.getCollectInfo1();
        collectInfo.enqueue(mCallback);
    }

    @Override
    public List<CollectBean.FavoriteBean> getDataBean(Response<CollectBean> response) {
        return response.body().getFavorites();
    }

    public CollectSoftPresenter(OurTabBaseFragment ourTabBaseFragment) {
        super(ourTabBaseFragment);
    }
/*



    private SoftFragment mSoftFragment;

    List<CollectBean.FavoriteBean> favorites = new ArrayList<>();
    //TODO:基类要有的成员变量
    protected int mFlag;

    public CollectSoftPresenter(SoftFragment softFragment) {
        mSoftFragment = softFragment;
    }

    @Override
    protected void getFailureData(Throwable t) {
        t.printStackTrace();
    }

    @Override
    protected void getSuccessData(Response<CollectBean> response) {
        CollectBean body = response.body();
        List<CollectBean.FavoriteBean> been = body.getFavorites();

        //TODO:空集合，listView，Adapter,mFlag,访问网络之后拿到的been（5个元素）
        {
            if (mFlag == 0){
                        favorites.removeAll(favorites);
                        favorites.addAll(been);
                        if (this.favorites.size() < 20) {
                            mSoftFragment.mSoftList.setHasMoreItems(false);
                        }
                    } else {
                        favorites.addAll(been);
                        if (favorites.size() < 20 * (mFlag+1)) {
                            mSoftFragment.mSoftList.setHasMoreItems(false);
                        }
                    }
            mSoftFragment.mSoftAdapter.setDatas(favorites);

            mSoftFragment.mSoftList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                    Log.d("bbbbb",i+"");
                    Intent intent = new Intent(mSoftFragment.getActivity(), DetailActivity.class);
                    intent.putExtra("been",favorites.get(i));
                    mSoftFragment.getActivity().startActivity(intent);
                }
            });
        }

    }

    @Override
    public void getData(int page) {
        mFlag = page;
        Call<CollectBean> collectInfo = mRetrofitInterface.getCollectInfo();
        collectInfo.enqueue(mCallback);
    }
*/

}
